<?php require_once('../../core/import.php');?>
<?php User::Permission('USER_ADD'); ?>
<?php
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
		
		//exit($PassWords);
        #添加数据
		$UserName=Functions::FormArgs('Username');
		$Password=Functions::FormArgs('Password');
		$Password_Again=Functions::FormArgs('Password_Again');
		$ClassID=Functions::FormArgs('ClassID');
		$M_locked=Functions::FormArgs('M_locked');
		$is_i=Functions::FormArgs('is_i');
		$Modular=Functions::FormArgs('Modular');
		$Modulars='';
		$Functions='';
		if(count($Modular)>0){
			foreach($Modular as $Value){
				$Modulars.=$Value.',';	
			}
		}
		for($j=0;$j<$is_i;$j++){
			$Function=Functions::FormArgs('Function_'.$j);
			if(count($Function)>0){
				foreach($Function as $Value){
					$Functions.=$Value.',';	
				}
			}
		}
		$Permissions=$Modulars.$Functions;
		$PassWord=User::EncryptPassword($Password,$UserName);
        $Data=array
        (
            'Username'=>$UserName,
			'Login_Datetime'=>date('Y-m-d G:i:s'),
			'Login_Count'=>0,
            'Datetime'=>date('Y-m-d G:i:s')
        );
		if($UserName=='') 
		{
			exit('{"Number":"2","Description":"请输入账号！"}');	
		}
		else
		{
			$Usernames=DB::GetRows("select ID,Username from management_user where Username='$UserName' order by ID asc");
			if($Usernames){
				exit('{"Number":"2","Description":"该账号已被注册！"}');		
			}
		}
		if($Password==$Password_Again) 
		{
			$Data['Password']=$PassWord;
		}
		else
		{
			exit('{"Number":"2","Description":"重复输入密码错误！"}');	
		}
		if($ClassID=='null') 
		{
			$Data['Permissions']=$Permissions;
			$Data['RoleID']=null;
		}
		else
		{
			$Data['RoleID']=$ClassID;
		}
		if($M_locked==1) 
		{
			DB::Insert('management_user_locked',array(
				'User'=>$UserName,
				'Datetime'=>date('Y-m-d G:i:s')
			));
		}
        DB::Insert('management_user',$Data);
        echo '{"Number":"0","Description":"成功执行"}';
    }
?>